/**
 * Key
 */
var DMX = {
    Version: '1.0',
    Browser: {
        IE:navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent.indexOf("iPanel") == -1 && navigator.userAgent.indexOf("Coship")==-1 && navigator.userAgent.indexOf("DVN")==-1,//!!(window.attachEvent && !window.opera),
        Firefox:(navigator.userAgent.indexOf('Firefox/14') >= 0 || navigator.userAgent.indexOf('Firefox/15') >= 0) && navigator.userAgent.indexOf("iPanel") == -1 && navigator.userAgent.indexOf("Coship")==-1 && navigator.userAgent.indexOf("DVN")==-1,
        Chrome:navigator.userAgent.indexOf('Chrome') >= 0 ,
        androidSkyworth:navigator.userAgent.indexOf("Android")>=0 && navigator.userAgent.indexOf("Skyworth")>=0,  //创维安卓盒子
    }
};
/**
 * browser type
 * default IE
 */
var KEY = {};
/*if (DMX.Browser.IE || DMX.Browser.Firefox || DMX.Browser.Chrome) {
	document.onkeydown = pageEvent;
}else{
	document.onkeypress = pageEvent;
}
function pageEvent(e){
	htEventHandle(event.keyCode);
}*/

if(DMX.Browser.androidSkyworth){
    //创维安卓盒子
    KEY = {
        UP:28,
        DOWN:29,
        LEFT:30,
        RIGHT:31,
        ENTER:13,
        PAGEUP:120,
        PAGEDOWN:121,
        BACK:32,
        EXIT:114,
        NUMBER0:48,
        NUMBER1:49,
        NUMBER2:50,
        NUMBER3:51,
        NUMBER4:52,
        NUMBER5:53,
        NUMBER6:54,
        NUMBER7:55,
        NUMBER8:56,
        NUMBER9:57,
        VOLUMNUP:190,
        VOLUMNDOWN:188,
        VOLUMNNO:0x28,//静音
        STOP:48,//播放时按退出响应的键值
        STOPPOINT:65,//播放时按后退响应的键值
        STOP1:48,
        STOPPOINT1:65,
        MENU:113,
        F1:96,
        F2:97,
        F3:98,
        F4:99,
        END:0x20, //播放结束事件
        END1:0x2B,
        INFO:112//信息
    };
}else {
    KEY = {
        UP:38,
        DOWN:40,
        LEFT:37,
        RIGHT:39,
        ENTER:13,
        PAGEDOWN:121,
        PAGEUP:120,
        BACK:32,
        EXIT:114,
        NUMBER0:48,
        NUMBER1:49,
        NUMBER2:50,
        NUMBER3:51,
        NUMBER4:52,
        NUMBER5:53,
        NUMBER6:54,
        NUMBER7:55,
        NUMBER8:56,
        NUMBER9:57,
        VOLUMNUP:0x29,
        VOLUMNDOWN:0x27,
        VOLUMNNO:0x28,//静音
        STOP:48,//播放时按退出响应的键值
        STOPPOINT:80,//播放时按后退响应的键值
        STOP1:65,
        STOPPOINT1:68,
        MENU:0x71,
        F1:96,
        F2:97,
        F3:98,
        F4:99,
        END:0x2B, //播放结束事件
        END1:0x2B,
        INFO:112 //信息
    };
}

function getCaSerialNum(){
    return CA.serialNumber;
}
function getStbSerialNum(){
    return hardware.STB.serialNumber;
}
function getHelpTailAddr(){
    var a = "0.0.0.0";
    //var ethernet = Network.ethernets[0];
    //var ip = ethernet.IPs;
    //		if(ip.length > 0){
    //		a = ip[0].IPAddress;
    //	}
    var currIp = a;
    var caSerialNum =	CA.serialNumber;
    var stbSerialNum =hardware.STB.serialNumber;
    //alert(currIp);
    //alert(caSerialNum);
    //alert(stbSerialNum);
    var codeStr = "Y-coship-coship" + currIp + "-etc";
    var helpTailAddr = "cardid=" + caSerialNum + "&clientid=" + stbSerialNum + "&method=&channel=0000:000:00:0000&code=" + codeStr + "&uitype=" + 1;
    return helpTailAddr;
}

function getUserId(){
    //alert(LoginInfo.userId);
    return LoginInfo.userId;
}

/**
 * 宏天按数字键进入直播
 */
var _gIndex = "";
var _gIndexTimeoutId;
function realEnterVod2(lcn){
    Utility.startApkByIntent("com.skyworthdigital.action.START_DVB", "xmpp://channel_change_lcn"+lcn+";");
}
function htEventHandle(e){
    e = window.event || e;
    var keyCode = e.which || e.keyCode;
    switch(keyCode){
        case 48:
        case 49:
        case 50:
        case 51:
        case 52:
        case 53:
        case 54:
        case 55:
        case 56:
        case 57:
        {
            if(_gIndexTimeoutId != undefined){
                clearTimeout(_gIndexTimeoutId);
            }
            var curI = 	keyCode-48;
            if(_gIndex == ""){
                _gIndex = "" + curI;
            }else{
                _gIndex = _gIndex + "" +curI;
            }
            document.getElementById("pindaoNo").innerHTML=_gIndex;
            _gIndexTimeoutId = setTimeout(function(){
                realEnterVod2(_gIndex);
            }, 5000);
        }
            break;
        case KEY.ENTER:{
            if(_gIndex != ""){
                realEnterVod2(_gIndex);
            }
        }
            break;
        case KEY.EXIT:{
            grabEvent(e)
        }
            break;
        case KEY.BACK:{
            grabEvent(e)
        }
            break;
    }
}